package com.stormrage.edu.dao.learn.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.learn.LeaTermDao;
import com.stormrage.entity.learn.LeaTerm;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: LeaTermDaoImpl.java
 * @Package com.stormrage.edu.dao.learn.impl
 * @Description: 学期 Dao
 * @author www.stormragetech.com
 * @date 2016年4月17日
 * @version V1.0
 */
@Repository
public class LeaTermDaoImpl extends MysBaseDao implements LeaTermDao {

	private static final Logger logger = LoggerFactory.getLogger(LeaTermDaoImpl.class);

	@Override
	public LeaTerm queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryById 】-【 STARTED 】");

		final String query = "SELECT * FROM lea_term WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		LeaTerm entity = queryObject(query, LeaTerm.class, map);

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public LeaTerm queryByIdStudy(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryById 】-【 STARTED 】");

		final String query = "SELECT * FROM lea_term WHERE id = :id AND now() > study_date_start AND now() < study_date_end";
		logger.debug(" 数据库执行语句为 " + query);

		LeaTerm entity = queryObject(query, LeaTerm.class, map);

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public LeaTerm queryByMajorId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryByMajorId 】-【 STARTED 】");

		final String query = "SELECT * FROM lea_term WHERE major_id = :majorId AND now() < exam_date_end";
		logger.debug(" 数据库执行语句为 " + query);

		LeaTerm entity = queryObject(query, LeaTerm.class, map);

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryByMajorId 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public LeaTerm queryForMajor(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryForMajor 】-【 STARTED 】");

		final String query = "SELECT * FROM lea_term WHERE major_id = :majorId AND now() > apply_date_start AND now() < apply_date_end";
		logger.debug(" 数据库执行语句为 " + query);

		LeaTerm entity = queryObject(query, LeaTerm.class, map);

		logger.debug(" 【 Dao 】-【 LeaTermDao 】-【 QueryForMajor 】-【 COMPLETED 】");
		return entity;

	}

}
